package ee.videorentalstore.protocols.commands;

import java.util.Arrays;
import java.util.List;

public abstract class Command 
{
	private final String COMMAND_DESCRIPTION_AND_CONTENTS_SPLITTING_CONSTANT = "----";
	
	public abstract String getCommandDescription();
	public abstract void executeCommand(String inputStreamInstructionsToProcess);
	
	
	protected List<String> getSplittedInputStreamInstructionsToProcess(
			String inputStreamInstructionsToProcess)
	{
		String[] splittedClientInput = inputStreamInstructionsToProcess.split(
				COMMAND_DESCRIPTION_AND_CONTENTS_SPLITTING_CONSTANT);
		List<String> splittedNetInList = Arrays.asList(splittedClientInput); 
		return splittedNetInList; 
	}
	
	
	protected Integer getSpecificIntegerValueOutOfSplittedInstructionsList(
			List<String> splittedInstructionsList, 
			int positionOfAWantedIntegerValueInSplittedInstructionsList)
	{
		Integer integerWanted = null;
		try {
			integerWanted = Integer.parseInt(splittedInstructionsList.get(
					positionOfAWantedIntegerValueInSplittedInstructionsList).trim());
		} catch (Exception e) {
			System.err.println("ERROR: integer value wanted could not be parsed!");
		}
		
		return integerWanted;
	}

	
	protected String getSpecificStringValueOutOfSplittedInstructionsList(
			List<String> splittedInstructionsList, 
			int positionOfAWantedStringValueInSplittedInstructionsList)
	{
		String stringValueWanted = null;
		try 
		{
			stringValueWanted = splittedInstructionsList.get(
					positionOfAWantedStringValueInSplittedInstructionsList).trim();
		} catch (Exception e) {}
		
		return stringValueWanted;
	}
}
